using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using UnityEngine;
using Voodoo.Sauce.Internal.Analytics;

namespace Voodoo.Sauce.Privacy
{
	public static class PrivacyUtils
	{
		public enum GDPRType
		{
			Voodoo = 0,
			VoodooSP = 1,
			ATT = 2
		}

		private const string PopupVersion = "2.2";

		private static readonly PrivacyInfoList _analyticsSDKs = new PrivacyInfoList();

		private static readonly PrivacyInfoList _adNetworkSDKs = new PrivacyInfoList();

		private static bool _areSDKsInitialized = false;

		private static readonly Regex ValidateEmailRegex = new Regex("^[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$");

		public static GDPRType GetGDPRType()
		{
			return GDPRType.Voodoo;
		}

		public static string GetLocale()
		{
			return "ZZ";
		}

		public static string GetOsType()
		{
			return "unknown";
		}

		public static string GetUserStatus()
		{
			if (!AnalyticsStorageHelper.Instance.IsFirstAppLaunch())
			{
				return "old";
			}
			return "new";
		}

		public static string GetVSVersion()
		{
			return null;
		}

		public static string GetAppVersion()
		{
			return Application.version;
		}

		public static string GetPopupVersion()
		{
			return "2.2";
		}

		public static bool IsValidEmail(string email)
		{
			return ValidateEmailRegex.IsMatch(email);
		}

		public static string[] GetAdNetworkNames()
		{
			return _adNetworkSDKs.GetNames();
		}

		public static IEnumerable<string> GetAdvertisingPrivacyPolicyUrls()
		{
			return _adNetworkSDKs.GetPrivacyPolicyUrls();
		}

		public static string[] GetAnalyticsNames()
		{
			return _analyticsSDKs.GetNames();
		}

		public static IEnumerable<string> GetAnalyticsPrivacyPolicyUrls()
		{
			return _analyticsSDKs.GetPrivacyPolicyUrls();
		}

		public static IEnumerable<string> GetPrivacyPolicyUrls()
		{
			return _analyticsSDKs.Select((PrivacyInfo info) => info.Name).Concat(_adNetworkSDKs.Select((PrivacyInfo info) => info.Name));
		}
	}
}
